//
//  CustomTipSubPanel.m
//  MobileAppsTipApp
//
//  Created by jcotter on 10/20/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "CustomTipSubPanel.h"


@implementation CustomTipSubPanel

@synthesize textField_Subtotal;
@synthesize texField_guestName;
@synthesize slider_tip;
@synthesize m_guest, parentCustomTipView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    m_guest = [Guest alloc];
    
    [m_guest settName:@""];
    [m_guest setUseTaxInTip:false];
    [m_guest setSubtotal:0];
    [m_guest setTipPerc:.15];
    [m_guest setTaxAmount:0];
    
    
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if(textField == texField_guestName)
    {
        [m_guest settName:textField.text];
    }
    else if(textField == textField_Subtotal)
    {
        NSString *mysubtotal = textField.text;
        [m_guest setSubtotal:[mysubtotal doubleValue]];
    }
    [parentCustomTipView updateUI];
    
    
    NSLog(@"typed %@", textField.text); // %@ for any NSObject
    return YES; // allow the default return behavior as well 
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    [texField_guestName resignFirstResponder];
    [textField_Subtotal resignFirstResponder];
}
@end
